#!/usr/bin/perl

use strict;
use warnings;
use Smart::Comments;

use lib '../lib';

use POE qw(Component::Gearman);
use PoeHelper;

use Utils;

my @event = qw(foo done partially_completed);

# 创建 POE 主 Session
spawnSession( @event );

run POE::Kernel;
exit 0;

event _start {
    runlog( TA => 'TA 启动中...' );

    alias_set( 'mainSession' );

    spawn POE::Component::Gearman::Client {
        Alias               => 'GearmanClient',
        JobServer           => '127.0.0.1',
        ReconnectInterval   => 3,
        Prefix              => '',
    };

    yield 'foo';
}

event foo {
    my $lines = 'line 1
line 2
line 3
line 4
line 5
line 6';

    post GearmanClient => do => reverse => $lines => {
        on_complete     => [ qw( done test ) ],
        on_data         => [ qw( partially_completed test ) ],
    };
}

event done( $cbArgs, $data ){
    print "[@$cbArgs] done: $data\n";
}

event partially_completed( $cbArgs, $data ){
    print "[@$cbArgs] partially_completed: $data";
}
